package org.jshand.jxc.business;

import java.awt.Dialog.ModalExclusionType;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import org.jshand.jxc.util.DimensionUtils;
import org.jshand.jxc.util.DimensionUtils.BusiDime;

public class LoginFrame extends JFrame {
	private static final long serialVersionUID = 1L;
	
	final static int width = 360; 
	final static int height = 300; 
	
	
	public LoginFrame() throws HeadlessException {
		super();
		this.init();
		this.initCom();
		
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		this.addMouseListener(new MouseAdapter() {

			@Override
			public void mousePressed(MouseEvent e) {
				if(e.getButton() != 3 ){
					return;
				}
				
				System.out.println("press");
				final JPopupMenu popMenu = new JPopupMenu();
				popMenu.add(new JMenuItem("abc"));
				popMenu.add(new JMenuItem("abc"));
				popMenu.add(new JMenuItem("abc"));
				popMenu.add(new JMenuItem("abc"));
				JButton btn = new JButton("btn");
				btn.addMouseListener(new MouseAdapter() {

					@Override
					public void mouseClicked(MouseEvent e) {
						System.out
								.println("LoginFrame.LoginFrame().new MouseAdapter() {...}.mousePressed(...).new MouseAdapter() {...}.mouseClicked()");
						popMenu.setVisible(false);
					}
				});
				
				popMenu.add(btn);
				popMenu.show(e.getComponent(), e.getX(), e.getY());
			}
			
		});
		this.setVisible(true);
	}
	
	
	/**
	 * 初始化创建 组件
	 */
	private void initCom() {
		
		int basex = 40;
		int basey = 50;
		
		Font font = new  Font("宋体",Font.BOLD, 18);
		
		JPanel p = new JPanel(null);
		
		JLabel lableUserName = new JLabel("用户名 :");
		lableUserName.setBounds(basex, basey, 80,35);
		lableUserName.setFont(font);
		p.add(lableUserName);
		
		JLabel lablePass = new JLabel("密  码 :");
		lablePass.setBounds(lableUserName.getX(), lableUserName.getY()+lableUserName.getHeight()+20, 80,35);
		lablePass.setFont(font);
		p.add(lablePass);
		
		
		final JTextField userName = new JTextField(20);
		userName.setBounds(lableUserName.getX()+lableUserName.getWidth()+5,lableUserName.getY()+6, 160,25);
		p.add(userName);
		
		final JTextField passWord = new JPasswordField(20);
		passWord.setBounds(userName.getX(), lablePass.getY()+6	, 160,25);
		p.add(passWord);
		
		JButton lgoinBtn = new JButton("登录");
		lgoinBtn.setBounds(lablePass.getX()+50, lablePass.getY()+lablePass.getHeight()+30, 60,25);
		p.add(lgoinBtn);
		
		//重置按钮
		JButton resetBtn = new JButton("重置");
		resetBtn.setBounds(lgoinBtn.getX()+lgoinBtn.getWidth()+15, lgoinBtn.getY(), 60,25);
		p.add(resetBtn);

		
		
		lgoinBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println("登录...");
				MainFrame main = new MainFrame();
				main.setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
				LoginFrame.this.setVisible(false);
			}
		});
		

		resetBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println("重置..");
				userName.setText("");
				passWord.setText(null);
			}
		});
		
		this.setContentPane(p);
	}



	/**
	 * 初始化信息
	 */
	private void init() {
		this.setTitle("进销存管理系统....");
		
		BusiDime xy = DimensionUtils.getXY(width, height);
		
		this.setBounds(xy.getA(), xy.getB(), width, height);
		
		setResizable(false);
		
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		List user = new ArrayList();
		
	}





	public static void main(String[] args) {
		
		new LoginFrame();
		
	}
	
}
